package jwr.ex2;

public class Reserve extends ReserveVO{
	private String sSeats[] = new String[10];
	private String aSeats[] = new String[10];
	private String bSeats[] = new String[10];

	public Reserve() {
			for(int j = 0;j <10;j++){
				sSeats[j] = "-"+(j+1)+"-"; 
				aSeats[j] = "-"+(j+1)+"-"; 
				bSeats[j] = "-"+(j+1)+"-"; 
			}
	}
	
	public String getsSeat() {
		String result="S석 >> ";
		for(int i = 0; i < 10; i++){
			result += sSeats[i]+" ";
		}
		return result;
	}
	
	public String getaSeat() {
		String result="A석 >> ";
		for(int i = 0; i < 10; i++){
			result += aSeats[i]+" ";
		}
		return result;
	}

	public String getbSeat() {
		String result="B석 >> ";
		for(int i = 0; i < 10; i++){
			result += bSeats[i]+" ";
		}
		return result;
	}

	@Override
	public boolean newReserve(ReserveVO rs) {
		switch(rs.getRating()){
			case 1:
				sSeats[rs.getNum()-1] = rs.getName(); 
				break;
			case 2:
				aSeats[rs.getNum()-1] = rs.getName();
				break;
			case 3:
				bSeats[rs.getNum()-1] = rs.getName();
				break;
		}
		return true;
	}
	public boolean compare(){
		boolean isResult=true;
		switch(getRating()){
			case 1:
				if(sSeats[getNum()-1].equals("-"+getNum()+"-") ){
					isResult = true;
				}else{
					isResult = false;
				}
				break;
			case 2:
				if(aSeats[getNum()-1].equals("-"+getNum()+"-")){
					isResult = true;
				}else{
					isResult = false;
				}
				break;
			case 3:
				if(bSeats[getNum()-1].equals("-"+getNum()+"-")){
					isResult = true;
				}else{
					isResult = false;
				}
				break;
		}
		return isResult;
	}
	@Override
	public String readReserve() {
		String result = getsSeat()+"\n"+getaSeat()+"\n"+getbSeat();
		return result;
	}
	@Override
	public boolean removeReserve() {
		switch(getRating()){
		case 1:
			for(int i = 0 ; i < 10 ; i++){
				if(sSeats[i].equals(getName())){
					sSeats[i] = "-"+(i+1)+"-";
				}
			}
			break;
		case 2:
			for(int i = 0 ; i < 10 ; i++){
				if(aSeats[i].equals(getName())){
					aSeats[i] = "-"+(i+1)+"-";
				}
			}
			break;
		case 3:
			for(int i = 0 ; i < 10 ; i++){
				if(bSeats[i].equals(getName())){
					bSeats[i] = "-"+(i+1)+"-";
				}
			}
			break;
	}
		return true;
	}
	
}
